package com.jlnk.androidfmc.room;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.jlnk.androidfmc.App;

public class AddressDB extends SQLiteOpenHelper {

  private static final String DB_NAME = "shop";
  private static final int DB_VERSION = 1;

  private static volatile AddressDB INSTANCE;

  public AddressDB(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
  }

  public static AddressDB getDatabase(final Context context) {
    if (INSTANCE == null) {
      synchronized (AddressDB.class) {
        if (INSTANCE == null) {
          INSTANCE = new AddressDB(App.getContext());
        }
      }
    }
    return INSTANCE;
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    String initAddressSQL =
        "CREATE TABLE IF NOT EXISTS address ("
            + "id INTEGER PRIMARY KEY AUTOINCREMENT, "
            + "name TEXT, "
            + "phone TEXT, "
            + "province TEXT, "
            + "city TEXT, "
            + "district TEXT, "
            + "addressDetail TEXT, "
            + "isDefault INTEGER)";

    db.execSQL(initAddressSQL);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  }
}
